package com.android.fastride.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.android.fastride.activity.base.BaseActivity;


/**
 * 代理Fragment的Activity
 * Created by pengyuantao on 2017/10/13 16:58.
 */

public class ProxyFragmentActivity extends BaseActivity {

    //传入Fragment对应Class
    public static final String KEY_FRAGMENT_CLZ = "KEY_FRAGMENT_CLZ";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置透明状态栏
//		setTransparentStatusBar();
        Class serializableExtra = (Class) getIntent().getSerializableExtra(KEY_FRAGMENT_CLZ);
        if (serializableExtra == null) {
            throw new RuntimeException("ProxyFragmentActivity only support static start(Context," +
                    "Class) to start this activity");
        }
        Bundle bundle = getIntent().getBundleExtra("BUNDLE");
        if (bundle != null) {
            bindOneFragmentWithArgument(serializableExtra, bundle);
        } else {
            bindOneFragment(serializableExtra);
        }
    }

    /**
     * 根据一个Fragment 启动一个Activity
     *
     * @param context
     * @param fragmentClass
     */
    public static void start(Context context, Class<? extends Fragment> fragmentClass) {
        Intent intent = new Intent(context, ProxyFragmentActivity.class);
        intent.putExtra(KEY_FRAGMENT_CLZ, fragmentClass);
        context.startActivity(intent);
    }

    /**
     * 根据一个Fragment 启动一个Activity
     *
     * @param context
     * @param fragmentClass
     */
    public static void start(Context context, Class<? extends Fragment> fragmentClass, Bundle
            bundle) {
        Intent intent = new Intent(context, ProxyFragmentActivity.class);
        intent.putExtra(KEY_FRAGMENT_CLZ, fragmentClass);
        intent.putExtra("BUNDLE", bundle);
        context.startActivity(intent);
    }
}
